{{ partial "header.html" . }}

{{- if .IsHome -}}
 {{- partial "tagline.html" . -}}
{{- else -}}
<h1>{{ .Title }}</h1>
{{- end -}}
<hr>
{{- if .Content -}}
{{- .Content -}}
{{- end -}}

<div class="archive list">

  {{- range (.Paginate (.Pages.GroupByDate "2006")).PageGroups  }}  
  <h2 class="archive-title">{{ .Key }}</h2>
  {{ range .Pages.GroupByDate "2006-01-02" }}
  {{ range .Pages }}
  <p>
    <span class="date year">{{ .Date.Format "2006" }}-</span><span class="date month">{{ .Date.Format "01-02" }}</span>&nbsp;
    <a href="{{ .RelPermalink }}">{{ .Title }}</a>
  </p>
  {{ end }}
  {{ end }}
  {{ end -}}
  
<br>
{{- if or (.Paginator.HasPrev) (.Paginator.HasNext) }}
<nav class="pagination" role="pagination">
  <span class="nav-prev">{{ if .Paginator.HasPrev }}&larr; <a href="{{ .Paginator.Prev.URL }}">Prev</a>{{ end }}</span>
  <span>&nbsp;{{ .Paginator.PageNumber }} / {{ .Paginator.TotalPages }}&nbsp;</span>
  <span class="nav-next">{{ if .Paginator.HasNext }}<a href="{{ .Paginator.Next.URL }}">Next</a>&rarr; {{ end }}</span>
</nav>
{{ end }}

<!-- 用左右键翻页：https://github.com/yihui/yihui.name/blob/master/layouts/partials/foot_custom.html -->
<script type="text/javascript">
document.addEventListener('keyup', function(e) {
  if (e.target.nodeName.toUpperCase() != 'BODY') return;
  var url = false;
  if (e.which == 37) {  // Left arrow
    {{ if .Paginator.HasPrev }}
    url = '{{ .Paginator.Prev.URL }}';
    {{ end }}
  } else if (e.which == 39) {  // Right arrow
    {{ if .Paginator.HasNext }}
    url = '{{ .Paginator.Next.URL }}';
    {{ end }}
  }
  if (url) window.location = url;
});
</script>

</div>
{{ partial "footer.html" . }}
